package com.sumainfor.pc.market.service.gmio;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.CompuUtils;
import com.sumainfor.pc.market.dao.CommunityGetMapper;
import com.sumainfor.pc.market.dao.gmio.TcmktPactNextPaIdMapper;
import org.apache.commons.collections.MapUtils;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 续租
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-04-30 18:54
 **/
@Service
public class TcmktPactNextPaIdService implements Serializable {

    @Autowired
    TcmktPactNextPaIdMapper tcmktPactNextPaIdMapper;

    @Autowired
    CommunityGetMapper communityGetMapper;


    public JsonResult forRenewal(Map<String,Object> params){
        JsonResult result = new JsonResult();
        System.out.println("接受的参数"+params);
        Map<String,Object> paramsMap = new HashMap<>();
        Integer coutOne = tcmktPactNextPaIdMapper.forRenewalOneCount(params);
        Integer coutTwo = tcmktPactNextPaIdMapper.forRenewalTwoCount(params);
        List<Map<String,Object>> TwoList = tcmktPactNextPaIdMapper.forRenewalTwo(params);
        System.out.println("coutOne"+coutOne);
        System.out.println("coutTwo"+coutTwo);
        System.out.println("TwoList"+TwoList);
        List<String> HouInfoIdList = new ArrayList<>();
        if (coutOne ==0||coutTwo==0){
            paramsMap.put("RenewalNumber",0);
            paramsMap.put("RenewalRate",0);
            return result.put(paramsMap);
        }else{
           double cout =  CompuUtils.div(coutTwo,coutOne,2);
           Integer zczs = new Integer(0);
           paramsMap.put("RenewalRate",cout);
            for (Map<String,Object> TwoMap:TwoList) {
                if(TwoMap.get("HouInfoId") !=null){
                    HouInfoIdList.add(MapUtils.getString(TwoMap,"HouInfoId"));
                }
            }
            System.out.println("HouInfoIdList"+HouInfoIdList);
            if (HouInfoIdList.size()>0){
                params.put("idList",HouInfoIdList);
                List<Map<String,Object>> HdList = communityGetMapper.getCommunityListHid(params);
                for (Map<String,Object> TwoMap:TwoList) {
                    for (Map<String,Object> HdMap:HdList) {
                        if (MapUtils.getString(TwoMap, "HouInfoId") != null && MapUtils.getString(HdMap, "HouInfoId") != null && MapUtils.getString(TwoMap, "HouInfoId").equals(MapUtils.getString(HdMap, "HouInfoId"))) {
                            TwoMap.putAll(HdMap);
                            System.out.println("TwoMap"+TwoMap);
                           zczs = zczs+MapUtils.getInteger(TwoMap,"RoomsNum");
                        }
                    }
                }
            }
            paramsMap.put("RenewalNumber",zczs);
            return result.put(paramsMap);
        }
    }


}
